package com.jie.myvhr.controller.salary;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jie.myvhr.bean.Employee;
import com.jie.myvhr.bean.RespBean;
import com.jie.myvhr.bean.Salary;
import com.jie.myvhr.service.EmpService;
import com.jie.myvhr.service.SalaryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jie
 * @date 2019/7/2 -9:02
 */
@RestController
@RequestMapping("/salary/sobcfg")
public class SalaryEmpController {

    @Resource
    private EmpService empService;
    @Resource
    private SalaryService salaryService;

    /**
     * 查询员工账套
     *
     * @param page 起始页
     * @param size 页大小
     * @return map
     */
    @GetMapping("emp")
    public Map<String, Object> getEmployeeByPage(@RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "10") Integer size) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(page, size);
        List<Employee> employeeByPageShort = empService.getEmployeeByPageShort();
        PageInfo<Employee> pageInfo = new PageInfo<>(employeeByPageShort);
        map.put("emps", pageInfo.getList());
        map.put("count", pageInfo.getTotal());
        return map;
    }

    /**
     * 修改账套
     */
    @PutMapping("/")
    public RespBean updateEmpSalary(Integer sid, Long eid) {
        if (salaryService.updateEmpSalary(sid, eid) == 1) {
            return RespBean.ok("修改成功");
        } else {
            return RespBean.error("修改失败");
        }
    }

    /**
     * 修改账套的时候查询出账套
     */
    @RequestMapping(value = "/salaries", method = RequestMethod.GET)
    public List<Salary> salaries() {
        return salaryService.getAllSalary();
    }
}
